﻿#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

class Solution {
public:
	void visitRoom(vector<vector<int>>& rooms, vector<bool>& isEnterRoom, int num) {
		for (int i = 0; i < rooms[num].size(); i++) {
			if (!isEnterRoom[rooms[num][i]]) {
				isEnterRoom[rooms[num][i]] = true;
				visitRoom(rooms, isEnterRoom, rooms[num][i]);
			}
		}
	}
	bool canVisitAllRooms(vector<vector<int>>& rooms) {
		vector<bool> isEnterRoom(rooms.size(), false);
		isEnterRoom[0] = true;
		visitRoom(rooms, isEnterRoom, 0);
		for (int i = 0; i < isEnterRoom.size(); i++) {
			if (!isEnterRoom[i]) 
				return false;
		}
		return true;
	}
};

int main()
{
	Solution sol;
	vector<vector<int>> test = { {1},{2},{3},{} };
	cout <<sol.canVisitAllRooms(test)<<endl;
}
